package com.onesports.intelligent.k12.polarlight.controller.wx.apply;

import com.onesports.framework.kit.common.valid.Json;
import com.onesports.intelligent.k12.polarlight.common.utils.ResultUtil;
import com.onesports.intelligent.k12.polarlight.constant.ApiPathConstants;
import com.onesports.intelligent.k12.polarlight.domain.dto.wx.CampusApplyDTO;
import com.onesports.intelligent.k12.polarlight.security.SecurityUtils;
import com.onesports.intelligent.k12.polarlight.service.wx.CampusApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author wangcx
 */
@Api(value = "小程序端", tags = "小程序端-社区申报")
@RestController
@RequestMapping(ApiPathConstants.WX_CAMPUS)
@RequiredArgsConstructor
@PreAuthorize("isAuthenticated()")
public class WxCampusController {

    private final CampusApplyService service;

    @PostMapping("/apply")
    @ApiOperation(value = "社区申请")
    public ResponseEntity campusApply(@Json @RequestBody CampusApplyDTO dto) {
        dto.setWxUserId(SecurityUtils.getAccountId());
        dto.setApplyPhone(SecurityUtils.getPhone());
        this.service.apply(dto);
        return ResultUtil.success("申请成功");
    }


}
